package org.f0rb.demo.model.user;


import org.f0rb.demo.dao.HibernateDAOImpl;

import java.util.List;

/**
 * UserDAO的实现类.
 *
 * Date: 2010-1-26
 * Time: 23:42:30
 * @author f0rb
 */
public final class UserDAOImpl extends HibernateDAOImpl<User> implements UserDAO {
    @Override
    public int countByUsername(String username) {
        return countByProperty(User.FIELD_USERNAME, username).intValue();
    }

    @Override
    public int countByNickname(String nickname) {
        return countByProperty(User.FIELD_NICKNAME, nickname).intValue();
    }

    @Override
    public User getByUsername(String username) {
        return uniqueByProperty(User.FIELD_USERNAME, username);
    }

    @Override
    public User getByUsername(User user) {
        return uniqueByProperty(User.FIELD_USERNAME, user.username);
    }

    @Override
    public void login(User user) {
        updateByNamedQuery("login", new Object[]{user.lastlogin, user.lasthost, user.id});
    }

    @Override
    public void logout(Integer id) {
        updateByNamedQuery("logout", id);
    }

    @Override
    public List<User> list(User o) {
        return listAll();
    }

    @Override
    public List<User> page(User o) {
        return page(o.getOffset(), o.getLimit());
    }
}